﻿using RBAC.LuFang.Domain.Traceability;
using RBAC.LuFang.Repository.lnterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RBAC.LuFang.Domin.Services.TraceabilityService
{
    public class deepprocessingService: IdeepprocessingService
    {
        private readonly IdeepprocessingRepository _deepService;
        private readonly IimgesRepository _imgService;

        public deepprocessingService(IdeepprocessingRepository deepService, IimgesRepository imgService)
        {
            _deepService = deepService;
            _imgService = imgService;
        }

        /// <summary>
        /// 反填深加工
        /// </summary>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        public async Task<deepprocessing> Getdeepprocessing(int goodsid)
        {
            try
            {
                var res = (await _deepService.GetAllAsync()).Where(x => x.goodsId == goodsid).FirstOrDefault();
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 显示深加工
        /// </summary>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        public async Task<List<deepprocessing>> Showdeepprocessing(int goodsid)
        {
            try
            {
                return await _deepService.Get(x => x.goodsId == goodsid);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 更新深加工
        /// </summary>
        /// <param name="deepprocessing"></param>
        /// <returns></returns>
        public async Task<int> Upddeepprocessing(deepprocessing deepprocessing)
        {
            try
            {
                return await _deepService.GetUpd(deepprocessing);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 删除食品安全信息
        /// </summary>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        public async Task<int> DelfootPic(int goodsid)
        {
            try
            {
                var res = await _imgService.GetByidAsync(goodsid);
                return await _imgService.Del(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 显示食品安全信息
        /// </summary>
        /// <param name="imgtype"></param>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        public async Task<List<imges>> ShowfootPic(string imgtype, int goodsid)
        {
            try
            {
                return await _imgService.Get(x => x.imgestype == imgtype && x.goodsId == goodsid);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 显示相关材料 原料
        /// </summary>
        /// <param name="imgtype"></param>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        public async Task<List<imges>> GetXiangpic(string imgtype, int goodsid)
        {
            try
            {
                return await _imgService.Get(x => x.imgestype == imgtype && x.goodsId == goodsid);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 删除相关材料 原料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DelXiangpic(int id)
        {
            try
            {
                var res = await _imgService.GetByidAsync(id);
                return await _imgService.Del(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 显示相关材料 辅料
        /// </summary>
        /// <param name="imgtype"></param>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        public async Task<List<imges>> GetXiangpicFu(string imgtype, int goodsid)
        {
            try
            {
                return await  _imgService.Get(x => x.imgestype == imgtype && x.goodsId == goodsid);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 删除相关材料 辅料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DelXiangpicFu(int id)
        {
            try
            {
                var res = await _imgService.GetByidAsync(id);
                return await _imgService.Del(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
